package com.example.payment.controller;

import com.example.common.req.payment.PaymentReq;
import com.example.common.resp.GlobalResult;
import com.example.common.resp.payment.PaymentResp;
import com.example.payment.service.PaymentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

@Slf4j
@RestController
@RequestMapping("/payment")
@Tag(name = "PaymentController", description = "支付操作")
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping(value = "/create")
    @Operation(summary = "创建支付信息")
    public GlobalResult<Long> create(@Validated @RequestBody PaymentReq req) {
        Long result = paymentService.create(req);
        String message = "Server Port:" + serverPort;
        return GlobalResult.success(message, result);
    }

    @GetMapping(value = "/get/{id}")
    @Operation(summary = "获取支付信息")
    public GlobalResult<PaymentResp> get(@NotNull @PathVariable("id") Long id) {
        PaymentResp payment = paymentService.get(id);
        String message = "Server Port:" + serverPort;
        return GlobalResult.success(message, payment);
    }
}
